/**
 * 
 */
package ro.dta.idbi.model.dynamicpattern;

import java.util.HashSet;
import java.util.Set;

import com.mxgraph.model.mxCell;
import com.mxgraph.model.mxGeometry;

/**
 * Atomic node in the dependency graph
 * 
 * @author Tudor Dobrila
 * 
 */
public class AtomicNode extends mxCell {

	private static final long serialVersionUID = -6579347040537883353L;

	/**
	 * Type of the operation contained by this node
	 */
	private String type;

	/**
	 * Name of the object affected by the operation
	 */
	private String name;

	/**
	 * Set of dependent objects
	 */
	private Set<String> dependentObjects;

	/**
	 * Atomic node class constructor
	 */
	public AtomicNode() {
		dependentObjects = new HashSet<String>();
		setVertex(true);
		setId(null);
		setConnectable(true);
		setGeometry(new mxGeometry(0, 0, 120, 20));
		setStyle("ATOM");
	}

	/**
	 * Atomic node class constructor
	 * 
	 * @param type
	 *            Type of the operation contained by this node
	 * @param name
	 *            Name of the object affected by the operation
	 * @param dependentObjects
	 *            Set of dependent objects
	 */
	public AtomicNode(String type, String name, Set<String> dependentObjects) {
		this();
		this.type = type;
		this.name = name;
		this.dependentObjects = dependentObjects;
		setValue(type);
	}

	/**
	 * Set the type of the operation contained by this node
	 * 
	 * @param type
	 *            New type of the operation contained by this node
	 */
	public void setType(String type) {
		this.type = type;
		setValue(type);
	}

	/**
	 * @return Type of the operation contained by this node
	 */
	public String getType() {
		return type;
	}

	/**
	 * @param name
	 *            Name of the object affected by this node
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return Name of the object affected by this node
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param dependentObjects
	 *            Set of dependent objects
	 */
	public void setDependentObjects(Set<String> dependentObjects) {
		this.dependentObjects = dependentObjects;
	}

	/**
	 * @return Get the objects that this atom depends on
	 */
	public Set<String> getDependentObjects() {
		return dependentObjects;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder("Type: ").append(getType()).append("\r\n");
		builder.append("Name: ").append(getName()).append("\r\nDependent objects:");
		for (String s : getDependentObjects()) {
			builder.append(s).append("; ");
		}
		return builder.toString();
	}
}
